package com.jindy.module.repairrecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.repairrecord.domain.RepairRecord;
import com.jindy.module.repairrecord.service.IRepairRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 机器维修记录Controller
 *
 * @author ruoyi
 * @date 2022-10-24
 */
@RestController
@RequestMapping("/module/repairRecord")
public class RepairRecordController extends BaseController
{
    @Autowired
    private IRepairRecordService repairRecordService;

    /**
     * 查询机器维修记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:repairRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairRecord repairRecord)
    {
        startPage();
        List<RepairRecord> list = repairRecordService.selectRepairRecordList(repairRecord);
        return getDataTable(list);
    }
    /**
     * 根据传入的机器编号查询其所有的机器维修记录列表
     */
    @GetMapping("/list2")
    public TableDataInfo list2(RepairRecord repairRecord){
        List<RepairRecord> list2 = repairRecordService.selectRepairRecordList2(repairRecord);
        return getDataTable(list2);
    }


    /**
     * 导出机器维修记录列表
     */
    @Log(title = "机器维修记录", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('module:repairRecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairRecord repairRecord)
    {
        List<RepairRecord> list = repairRecordService.selectRepairRecordList(repairRecord);
        ExcelUtil<RepairRecord> util = new ExcelUtil<RepairRecord>(RepairRecord.class);
        util.exportExcel(response, list, "机器维修记录数据");
    }

    /**
     * 获取机器维修记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:repairRecord:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(repairRecordService.selectRepairRecordById(id));
    }

    /**
     * 新增机器维修记录
     */
    @Log(title = "机器维修记录", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('module:repairRecord:add')")
    @PostMapping
    public AjaxResult add(@RequestBody RepairRecord repairRecord)
    {
        return toAjax(repairRecordService.insertRepairRecord(repairRecord));
    }

    /**
     * 修改机器维修记录
     */
    @Log(title = "机器维修记录", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('module:repairRecord:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody RepairRecord repairRecord)
    {
        return toAjax(repairRecordService.updateRepairRecord(repairRecord));
    }

    /**
     * 删除机器维修记录
     */
    @Log(title = "机器维修记录", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('module:repairRecord:delete')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(repairRecordService.deleteRepairRecordByIds(ids));
    }
}
